home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / strategy / xsok-1.000 / xsok-1 / xsok-1.01 / src / combine.c next >
C/C++ Source or Header  |  1994-11-24  |  1KB  |  54 lines

  1. #define _POSIX_SOURCE
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. static int stripcomments = 0;
  7.  
  8. static int copy(FILE *fout, char *s, int i) {
  9.     FILE *fp;
  10.     if (!(fp = fopen(s, "r")))
  11.     return 0;
  12.     if (i)
  13.     fprintf(fout, ";LEVEL %d\n", i);
  14.     while (fgets(s, 100, fp)) {
  15.     if (stripcomments) {
  16.         if (!strncmp(s, "; ", 2))
  17.         continue;
  18.         if (!strcmp(s, ";\n"))
  19.         continue;
  20.     }
  21.     fprintf(fout, "%s", s);
  22.     }
  23.     fclose(fp);
  24.     return 1;
  25. }
  26.  
  27. int main(int argc, char *argv[]) {
  28.     int c, i;
  29.     for (c = 1; c < argc; ++c) {
  30.     FILE *fout;
  31.     char s[100];
  32.     if (!strcmp(argv[c], "-s")) {
  33.         stripcomments = 1;
  34.         continue;
  35.     }
  36.     sprintf(s, "%s.def", argv[c]);
  37.     if (!(fout = fopen(s, "w"))) {
  38.         fprintf(stderr, "Cannot open output file %s\n", s);
  39.         exit(1);
  40.     }
  41.     sprintf(s, "%s/definitions", argv[c]);
  42.     if (!copy(fout, s, 0)) {
  43.         fprintf(stderr, "No file %s\n", s);
  44.         exit(1);
  45.     }
  46.     for (i = 1; i < 100; ++i) {
  47.         sprintf(s, "%s/screen.%02d", argv[c], i);
  48.         if (!copy(fout, s, i))
  49.         break;
  50.     }
  51.     }
  52.     return 0;
  53. }
  54.